#!/usr/bin/env python
import sys, os, getopt, argparse
from wedewoba.app import BrowserApp


def getFiles(dirName):
    """ get all files in dir """
    xfiles = []
    pos = len(dirName)+1
    for root, _dirs, files in os.walk(dirName):
        for f in files:
            xfiles.append(os.path.join(root, f)[pos:])
    return xfiles

def usage():
    """ usage info"""
    pass



def main():
    """ MAIN """

    # handel options and parameters of script
    parser = argparse.ArgumentParser()
    parser.add_argument('url')
    parser.add_argument('-c', dest="cachePath", metavar='PATH', type=str, help='path to cache directory')
    parser.add_argument('-C', dest="cookieJarFile", metavar='FILE', type=str, help='path to cookieJar file')
    parser.add_argument('-d', '--debug', action='store_true', help='enable debug console')
    parser.add_argument('-r', '--replace', metavar="FILE", action='append', help='replace FILE content', default=[])
    parser.add_argument('-i', '--insert', metavar="FILE", action='append', help='insert FILE', default=[])
    args = parser.parse_args()

    browserConf = {
            "debug": args.debug,
            "cookieJarFile": args.cookieJarFile,
            "cachePath": args.cachePath,
            "enableJavascript": True,
            "enablePlugins": True
            } 



    #
    # the application
    #
    app = BrowserApp(**browserConf)
    #browser = app.browser

    #for f in getFiles(os.getcwd()):
        #browser.replace(f, f)

    #for f in args.replace:
        #pattern = f.split(',')
        #pattern, rfile = pattern if len(pattern) == 2 else (pattern[0], pattern[0])
        #browser.replace.append(pattern, rfile)

    #for i in args.insert:
        #browser.inject(i)

    #app.run(args.url)



if __name__ == "__main__":
    main()
